;;; MSP430 + Sharp LS013B4DN04 LCD demo - "neko"
;;; A port of the classic japanese computer desktop toy (although I
;;; know it from the Macintosh Desk Accessory that came a year later..)
;;;
;;; Copyright Chris Baird <cjb@brushtail.apana.org.au> April 2015
;;;
;;; neko is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by the
;;; Free Software Foundation; either version 3 of the License, or (at your
;;; option) any later version.
;;;
;;; neko distributed in the hope that it will be useful, but WITHOUT
;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
;;; for more details.
;;;
;;; You should have received a copy of the GNU General Public License along
;;; with this program. If not, see <http://www.gnu.org/licenses/>.
;;; ----------------------------------------------------------------------

#include <msp430.h>

#define SP r1
#define SR r2

	POWER_CTRL	= 1	; P1.0
	LCD_ENABLE	= 8	; P1.3
	CHIP_SELECT	= 16	; P1.4
	SPI_CLK		= 32	; P1.5
	SPI_MOSI 	= 128	; P1.7

	M0		= 1	;1=Dynamic mode
	M2		= 4	;0=clear display

	xpos		= 0x200	;RAM-held globals
	ypos		= 0x201
	rand_state	= 0x202 ;16 bits
	rand_out	= 0x204	;8 bits
	dest_x		= 0x205
	dest_y		= 0x206
	dx		= 0x207
	dy 		= 0x208
	sx		= 0x209
	sy		= 0x20a
	err		= 0x20b
	stepsprite	= 0x20c	;16 bits
	stepsprite2	= 0x20e ;16 bits

	.section .text

;;; ----------------------------------------------------------------------

RESET:	mov.w #0x0280,SP
	mov.w #WDTPW+WDTHOLD, &WDTCTL ;stop Watchdog

	;;  configure CPU clock for 16MHz

	clr.b &DCOCTL
	mov.b &CALBC1_12MHZ,&BCSCTL1
	mov.b &CALDCO_12MHZ,&DCOCTL
	bis.b #6,&BCSCTL2 ;set SMCLK = MCLK/8
	bic.b #48,&BCSCTL2 ;set MCLK = CLK/1

	;; Fuck Hardware SPI

	mov.b #(POWER_CTRL+LCD_ENABLE), &P1OUT
	mov.b #(POWER_CTRL+LCD_ENABLE+CHIP_SELECT+SPI_CLK+SPI_MOSI), &P1DIR

	;;  wait a bit for everything electrical to settle down

	call #longdelay
	call #clearscreen

	mov.w #0xACE1, &rand_state
	mov.b #32, &xpos
	mov.b #32, &ypos

	;; ----------------------------------------

	mov.w #cycleSTART, r13
	call #drawcycle
main:
	;; maybe itchy.. 50% chance
	bit.b #1, &rand_out
	jnz main1
	mov.w #cycleSCRATCH, r13
	call #drawcycle3

main1: 	;; maybe groom.. 50% chance

	call #random
	bit.b #2, &rand_out
	jnz main2
	mov.w #cycleLICK, r13
	call #drawcycle3

main2:	;; maybe sleepy.. 25% chance

	bit.b #4+8, &rand_out
	jnz main3
	mov.w #cycleYAWN, r13
	call #drawcycle
	mov.w #cycleSLEEP, r13
	call #drawcycle6

main3:	;; uh-oh, time to run!

	mov.w #cycleAWAKE, r13
	call #drawcycle

	;; find a random destination

	call #random96
	mov.b r15, &dest_x
	call #random96
	mov.b r15, &dest_y

	;; calc gradient partials & gradient signs

	mov.b &dest_x, r5	;dx = abs (dest_x - neko_x);
	sub.b &xpos, r5
	bit.b #128, r5
	jne m3
	mov.b #1, &sx
	jmp m4
m3:	mov.b #255, &sx		;sx = neko_x < dest_x ? 1 : -1;
	mov.b #0, r4
	sub.b r5, r4
	mov.b r4, r5
m4:	mov.b r5, &dx

	mov.b &dest_y, r5	;dy = abs (dest_y - neko_y);
	sub.b &ypos, r5
	bit.b #128, r5
	jne m4a
	mov.b #1, &sy
	jmp m5
m4a:	mov.b #255, &sy		;sy = neko_y < dest_y ? 1 : -1;
	mov.b #0, r4
	sub.b r5, r4
	mov.b r4, r5
m5:	mov.b r5, &dy

	;; int err = (dx > dy ? dx : -dy)/2;

	mov.b #0, r4		;load r4 with -dy
	sub.b r5, r4		;(and r5 was already &dy)

	cmp.b &dx, &dy
	jhs m6			;jump if dy >= dx

	mov.b &dx, r4

m6:	rra.b r4		;/2
	mov.b r4, &err

	;; i = 3 + sx + 2*sy + 8*((2*dx)<dy) + 16*((2*dy)<dx);
	;; this determines which sprites to use depending
	;; on (dx,dy) .. an index into rundirection table

	mov.w #3, r4		;3 + sx
	add.b &sx, r4

	add.b &sy, r4		;2 * sy
	add.b &sy, r4

	mov.b #1, r5
	mov.b &dx, r6
	add.b r6, r6
	cmp.b r6, &dy
	subc.b #0, r5
	add.b r5, r5
	add.b r5, r5
	add.b r5, r5
	add.b r5, r4

	mov.b #1, r5
	mov.b &dy, r6
	add.b r6, r6
	cmp.b r6, &dx
	subc.b #0, r5
	add.b r5, r5
	add.b r5, r5
	add.b r5, r5
	add.b r5, r5
	add.b r5, r4

	add.b r4, r4
	add.w #rundirection, r4
	mov.w r4, &stepsprite
	add.w #2, r4
	mov.w r4, &stepsprite2
	;;

run_little_kitty:
	mov.b #5, r5

	call #clearscreen	;draw_kitty(250, step1_bits)
	mov.w &stepsprite, r14
	mov.w 0(r14), r15
	call #drawbitmap
	call #longdelay

run1:	cmp.b &xpos, &dest_x
	jne run2
	cmp.b &ypos, &dest_y
	jeq scratch

run2:	mov.b &err, r6		;e2 = err

	mov.b r6, r7		;if e2+dx > 0
	add.b &dx, r7
	bit.b #128, r7
	jne run3
	; err = err - dy, neko_x = neko_x + sx
	sub.b &dy, &err
	add.b &sx, &xpos

run3:	mov.b r6, r7		;if e2-dy < 0
	sub.b &dy, r7
	bit.b #128, r7
	jeq run4
	; err = err + dx, neko_y = neko_y + sy
	add.b &dx, &err
	add.b &sy, &ypos

run4:	mov.w &stepsprite, r6
	mov.w &stepsprite2, &stepsprite
	mov.w r6, &stepsprite2

	dec.b r5
	jne run1
	jeq run_little_kitty

scratch:
	mov.w #0, r13
	cmp.b #0, &xpos
	jne scr1
	mov.w #scratchLEFT, r13
scr1:	cmp.b #0, &ypos
	jne scr2
	mov.w #scratchTOP, r13
scr2:	cmp.b #63, &ypos
	jne scr3
	mov.w #scratchBOTTOM, r13
scr3:	cmp.b #63, &xpos
	jne scr4
	mov.w #scratchRIGHT, r13
scr4:	cmp.w #0, r13
	jeq scr5
	call #drawcycle6

scr5:	jmp main

;;; ----------------------------------------------------------------------

drawcycle6:
	call #drawcycle3
drawcycle3:
	call #drawcycle
	call #drawcycle
	;; fall through

drawcycle:
	;; cycle table entry address in r13
	;; screen coords in xpos,ypos
	;; cycletable: <delay><bitmap><delay>bitmap>
	;; exits with a clear screen
	mov.w 2(r13), r15
	call #drawbitmap
	mov.w 0(r13), r15
	call #delay
	mov.w 6(r13), r15
	call #drawbitmap
	mov.w 4(r13), r15
	call #delay
	;; fallthrough


clearscreen:
	bis.b #CHIP_SELECT, &P1OUT
	mov.b #M2, r15		  ;M0=0, M2=1
	call #send_spi
	call #send_spi		  ;send dummy data
	bic.b #CHIP_SELECT,&P1OUT ;disable display's SPI
	ret


;;; paint a 32x32 bitmap @r15 at (xpos,ypos)

drawbitmap:
	mov.w r15, r4
	;; set up starting multiple line command
	bis.b #CHIP_SELECT, &P1OUT
	mov.b #M0, r15
	call #send_spi
	push.w #32
	mov.b &ypos, r14
drawloop:
	mov.b r14, r15		;send line address
	call #send_spi

	cmp.b #0, &xpos
	jeq skiptab

	mov.b &xpos, r15	;do the 'tab'
	call #send_spi_blankpixels
skiptab:
	mov.b @r4+, r15		;send the 32 pixels..
	call #send_spi
	mov.b @r4+, r15
	call #send_spi
	mov.b @r4+, r15
	call #send_spi
	mov.b @r4+, r15
	call #send_spi

	mov.b #64, r15		;send the right margin
	sub.b &xpos, r15
	call #send_spi_blankpixels

	call #send_spi		;send dummy byte
	inc.b r14
	dec.w 0(SP)
	jnz drawloop

	call #send_spi		;dummy byte
	bic.b #CHIP_SELECT, &P1OUT
	incd.w SP
	ret


;;; ----------------------------------------------------------------------

	;; LSB transmission, byte in r15
send_spi:
        push.w #8
sendbit:
	rra.w r15
        jnc s0
        bis.b #SPI_MOSI,&P1OUT
        br #s1
s0:     bic.b #SPI_MOSI,&P1OUT
s1:	bis.b #SPI_CLK,&P1OUT
	bic.b #SPI_CLK,&P1OUT
        dec.w 0(SP)
        jnz sendbit
        incd.w SP
        ret

	;; send r15 blank pixels (zeroes r15)
send_spi_blankpixels:
	bis.b #SPI_MOSI,&P1OUT
ssbp1:	bis.b #SPI_CLK,&P1OUT
	bic.b #SPI_CLK,&P1OUT
        dec.b r15
        jnz ssbp1
        ret


;;; ----------------------------------------------------------------------

longdelay:
	mov.w #25, r15
delay:	push.w #30000
delay2:	dec.w 0(SP)
	jnz delay2
	incd.w SP
	dec.w r15
	jnz delay
	ret


;;; ----------------------------------------------------------------------
;;; I ripped this from a Stackoverflow posting..

random:	mov.b &rand_out, r15
	mov.b r15, r14
	and.b #66, r15
	jz rand1
	cmp.b #66, r15
	xor.w #1, SR		; invert carry flag
	jmp rand2
rand1:	clrc
rand2:	rlc.w &rand_state
	rlc.b r14
	mov.b r14, &rand_out
	ret


;;; get a random axis location, with a 25% chance
;;; if being 'clipped' to 0 or 63
;;; get number 0-x-127
;;; if x>95 then x=0
;;; if x>63 then x=63

random96:
	call #random
	mov.b &rand_out, r15
	and.b #127, r15
	cmp.b #96, r15
	jnc r96a
	clr.b #0, r15
r96a:	cmp.b #64, r15
	jnc r96b
	mov.b #63, r15
r96b: 	ret


;;; ----------------------------------------------------------------------

awake_bits:
	.byte 255,255,255,255,255,255,255,255,223,255,255,251,191,239,239,253
	.byte 127,215,215,254,255,182,219,255,249,187,187,159,231,123,189,231
	.byte 159,125,124,249,255,253,127,255,255,221,119,255,240,221,119,135
	.byte 255,221,119,255,255,253,127,255,255,197,70,255,255,251,191,255
	.byte 255,247,223,255,255,143,227,253,255,191,251,250,255,223,119,251
	.byte 255,239,175,253,255,247,223,254,255,244,95,254,127,243,158,253
	.byte 191,231,206,251,191,239,238,251,63,238,238,248,159,111,236,243,31
	.byte 0,1,240,255,255,255,255,255,255,255,255,255,255,255,255

down1_bits:
	.byte 255,127,254,255,255,191,253,255,255,191,253,255,255,191,253,255
	.byte 255,191,253,255,255,191,253,255,255,135,225,255,255,251,223,255
	.byte 255,253,191,255,255,254,127,255,127,255,255,254,127,239,239,253
	.byte 127,215,215,253,191,183,219,251,191,187,187,251,191,123,189,251
	.byte 191,125,124,251,191,253,127,251,159,253,127,243,63,253,127,249
	.byte 223,220,119,246,95,220,119,244,31,221,119,241,127,251,190,253,255
	.byte 240,31,254,255,131,131,255,255,63,248,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255

down2_bits:
	.byte 255,115,158,255,255,165,77,255,255,173,109,255,255,173,109,255
	.byte 255,158,245,254,255,158,249,254,255,254,255,254,255,254,255,254
	.byte 255,254,255,254,255,254,255,254,255,253,127,255,255,237,111,255
	.byte 255,214,215,254,255,182,219,254,255,186,187,254,255,122,189,254
	.byte 255,124,124,254,255,252,127,254,159,252,127,242,127,252,127,252
	.byte 255,220,119,254,255,220,119,254,255,221,119,255,255,249,62,255
	.byte 255,245,95,255,255,141,99,255,255,61,120,255,255,219,183,255,255
	.byte 219,183,255,255,203,167,255,255,231,207,255,255,255,255,255

dtogi1_bits:
	.byte 255,255,255,255,255,63,255,255,255,223,254,255,255,231,253,255
	.byte 255,223,251,255,255,191,251,255,255,135,195,255,255,251,191,255
	.byte 255,253,127,255,255,254,255,254,127,255,255,253,127,239,239,253
	.byte 127,215,215,253,63,183,219,249,207,186,187,230,247,123,189,223,7
	.byte 124,124,192,255,253,127,255,255,253,127,255,255,253,127,255,255
	.byte 221,119,255,255,221,119,255,255,217,119,255,255,249,190,255,255
	.byte 245,159,255,255,141,163,255,255,45,168,255,255,173,171,255,255
	.byte 165,171,255,255,171,171,255,255,171,235,255,255,255,255,255

dtogi2_bits:
	.byte 255,255,255,255,255,255,243,255,255,255,237,255,255,255,238,255
	.byte 255,127,247,255,255,127,251,255,255,15,195,255,255,247,191,255
	.byte 255,251,127,255,255,253,255,254,255,254,255,253,127,239,239,253
	.byte 127,215,215,253,63,183,219,249,207,186,187,230,247,123,189,223,7
	.byte 124,124,192,255,253,127,255,255,253,127,255,255,253,127,255,255
	.byte 221,119,255,255,221,119,255,255,221,55,255,255,251,62,255,255,243
	.byte 95,255,255,139,99,255,255,43,104,255,255,171,107,255,255,171,75
	.byte 255,255,171,171,255,255,175,171,255,255,255,255,255

dwleft1_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,31,255,255,255,227,248
	.byte 255,63,248,247,255,223,15,248,255,239,63,254,255,247,255,252,231
	.byte 240,255,249,215,242,255,251,183,246,239,251,119,238,247,251,247
	.byte 223,251,251,247,191,251,251,247,191,251,253,219,189,251,253,219
	.byte 189,251,253,216,13,247,253,251,255,247,253,219,255,247,253,251
	.byte 255,238,254,151,223,110,255,15,224,117,255,63,224,181,255,255,192
	.byte 179,255,255,1,219,255,255,115,200,255,255,255,227,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255

dwleft2_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,127,192,255
	.byte 255,31,191,193,255,111,199,190,255,223,118,199,255,159,141,251
	.byte 255,111,227,251,255,247,255,251,127,242,255,251,121,248,255,251
	.byte 33,243,255,251,13,231,255,253,29,206,255,254,121,159,127,255,251
	.byte 191,159,255,251,127,239,255,251,255,247,255,234,142,247,255,233
	.byte 246,251,255,235,126,251,255,251,191,253,255,211,207,254,255,231
	.byte 112,255,255,7,188,255,255,131,221,255,255,195,221,255,255,195,237
	.byte 255,255,231,241,255,255,255,255,255,255,255,255,255,255

dwright1_bits:
	.byte 255,255,255,255,255,255,255,255,255,248,255,255,31,199,255,255
	.byte 239,31,252,255,31,240,251,255,127,252,247,255,63,255,239,255,159
	.byte 255,15,231,223,255,79,235,223,247,111,237,223,239,119,238,223,223
	.byte 251,239,223,223,253,239,191,223,253,239,191,223,189,219,191,223
	.byte 189,219,191,239,176,27,191,239,255,223,191,239,255,219,127,119
	.byte 255,223,255,118,251,233,255,174,7,240,255,173,7,252,255,205,3,255
	.byte 255,219,128,255,255,19,206,255,255,199,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255

dwright2_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,3,254,255,131
	.byte 253,248,255,125,227,246,255,227,110,251,255,223,177,249,255,223
	.byte 199,246,255,223,255,239,255,223,255,79,254,223,255,31,158,223,255
	.byte 207,132,191,255,231,176,127,255,115,184,255,254,249,158,255,249
	.byte 253,223,255,247,254,223,255,239,255,223,255,239,113,87,255,223
	.byte 111,151,255,223,126,215,255,191,253,223,255,127,243,203,255,255
	.byte 14,231,255,255,61,224,255,255,187,193,255,255,187,195,255,255,183
	.byte 195,255,255,143,231,255,255,255,255,255,255,255,255

jare2_bits:
	.byte 255,255,255,255,255,255,255,255,255,207,255,255,255,47,255,255
	.byte 255,239,254,255,255,239,253,255,31,239,243,255,223,200,239,255
	.byte 223,231,223,255,191,255,190,255,191,255,189,255,191,255,175,255
	.byte 191,247,183,255,127,239,190,255,127,255,195,255,255,198,221,255
	.byte 255,253,187,255,255,131,131,255,255,191,187,255,255,223,185,255
	.byte 255,239,191,255,255,247,207,255,255,244,91,254,127,243,156,253
	.byte 191,231,254,251,191,239,254,195,63,238,250,184,159,111,252,195,31
	.byte 0,1,240,255,255,255,255,255,255,255,255,255,255,255,255

kaki1_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	.byte 255,249,255,255,255,229,255,255,255,157,255,255,255,125,255,255
	.byte 255,253,252,255,195,253,203,255,59,252,167,255,247,255,167,255
	.byte 247,223,167,255,239,239,39,255,223,247,231,254,223,55,231,253,31
	.byte 222,231,251,223,255,203,247,31,250,219,247,63,159,199,247,255,224
	.byte 239,247,255,247,223,247,255,244,223,247,127,243,222,243,191,231
	.byte 206,251,191,239,238,253,63,238,110,128,159,111,12,127,31,0,1,128
	.byte 255,255,255,255,255,255,255,255,255,255,255,255

kaki2_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	.byte 255,223,255,255,255,175,255,255,223,111,255,255,175,239,254,255
	.byte 111,247,253,255,239,246,251,255,239,249,247,255,239,255,247,255
	.byte 223,255,239,255,223,127,239,255,223,159,239,255,223,239,247,255
	.byte 31,126,6,252,223,159,231,251,31,58,240,247,63,31,255,247,255,96
	.byte 238,247,255,247,209,247,255,244,223,247,127,243,222,247,191,231
	.byte 206,251,191,239,238,251,63,238,110,128,159,111,12,127,31,0,1,128
	.byte 255,255,255,255,255,255,255,255,255,255,255,255

left1_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,255
	.byte 255,127,206,255,255,159,63,255,255,239,255,254,255,247,255,254
	.byte 243,251,255,253,235,251,255,251,155,253,255,247,119,252,254,237
	.byte 247,123,255,220,247,127,255,186,251,191,255,182,237,191,255,109
	.byte 237,191,255,91,237,120,255,61,60,126,255,254,254,191,252,254,253
	.byte 127,97,254,251,252,110,254,7,241,49,252,255,195,55,252,255,7,208
	.byte 252,255,15,199,255,255,31,231,255,255,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255

left2_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,223,255,255,31
	.byte 159,255,255,111,95,255,255,119,223,254,255,187,223,253,255,221
	.byte 207,243,255,238,247,239,63,247,219,207,199,247,219,223,249,247
	.byte 219,191,254,239,253,63,255,239,61,252,255,239,253,255,255,239,251
	.byte 255,255,239,135,255,255,223,127,248,247,223,127,254,207,63,63,255
	.byte 63,126,159,231,7,96,207,3,120,64,231,192,255,7,51,248,255,207,199
	.byte 252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255

ltogi1_bits:
	.byte 63,255,255,255,191,254,255,255,191,253,255,255,188,251,255,255
	.byte 200,231,255,255,240,223,255,255,248,191,255,255,216,191,255,255
	.byte 216,191,255,255,210,191,255,255,206,191,255,255,62,95,240,255,252
	.byte 255,207,255,242,255,191,255,199,63,127,255,143,223,255,254,191
	.byte 239,255,253,191,247,255,253,127,246,255,251,255,240,255,243,255
	.byte 243,255,239,255,227,255,223,255,199,252,185,255,1,254,114,255,112
	.byte 31,143,255,240,239,255,255,1,224,255,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255

ltogi2_bits:
	.byte 63,255,255,255,191,254,255,255,191,253,255,255,191,251,255,255
	.byte 190,231,255,255,206,223,255,255,246,191,255,255,218,191,255,255
	.byte 218,191,255,255,220,191,255,255,124,190,255,255,154,95,240,255
	.byte 250,255,207,255,22,254,191,255,206,63,127,255,240,223,255,254,254
	.byte 239,255,61,129,247,255,93,1,246,255,107,243,240,255,115,255,243
	.byte 255,191,255,227,255,223,255,199,252,225,255,1,254,254,255,112,31
	.byte 255,255,240,239,255,255,1,224,255,255,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255

mati2_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,239,239,255
	.byte 255,215,215,255,255,183,219,255,255,187,187,255,255,123,189,255
	.byte 255,125,124,255,255,253,127,255,255,221,119,255,255,221,119,255
	.byte 255,221,119,255,255,253,127,255,255,197,70,255,255,251,191,255
	.byte 255,247,223,255,255,143,227,255,255,191,251,255,255,223,247,255
	.byte 255,239,239,255,255,247,223,255,255,244,95,254,127,243,158,253
	.byte 191,231,206,251,191,239,238,251,63,238,238,128,159,111,236,115,31
	.byte 0,1,128,255,255,255,255,255,255,255,255,255,255,255,255

mati3_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,239,239,255
	.byte 255,215,215,255,255,183,219,255,255,187,187,255,255,123,189,255
	.byte 255,125,124,255,255,197,71,255,255,189,122,255,255,109,110,255
	.byte 255,177,29,255,255,189,125,255,255,189,125,255,255,187,189,255
	.byte 255,119,222,255,255,143,227,255,255,191,251,255,255,223,247,255
	.byte 255,239,239,255,255,247,223,255,255,244,95,254,127,243,158,253
	.byte 191,231,206,251,191,239,238,251,63,238,238,128,159,111,236,115,31
	.byte 0,1,128,255,255,255,255,255,255,255,255,255,255,255,255

right1_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,143,255,255
	.byte 255,115,254,255,255,252,249,255,127,255,247,255,127,255,239,255
	.byte 191,255,223,207,223,255,223,215,239,255,191,217,183,127,63,238,59
	.byte 255,222,239,93,255,254,239,109,255,253,223,182,255,253,183,218
	.byte 255,253,183,188,255,30,183,127,255,110,60,127,63,253,127,127,134
	.byte 254,191,127,118,63,223,63,140,143,224,63,236,195,255,63,11,224
	.byte 255,255,227,240,255,255,231,248,255,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255

right2_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,248,255,255,251
	.byte 246,255,255,249,230,255,255,250,221,255,127,251,187,255,191,251
	.byte 119,255,207,243,239,252,247,239,239,227,243,219,239,159,251,219
	.byte 247,127,253,219,247,255,252,191,247,255,63,188,247,255,255,191
	.byte 247,255,255,223,251,255,255,225,251,239,127,254,252,243,127,254
	.byte 126,252,255,252,6,240,231,249,2,6,192,243,224,255,3,231,243,255
	.byte 31,204,255,255,63,227,255,255,255,255,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255

rtogi1_bits:
	.byte 255,255,255,252,255,255,127,253,255,255,191,253,255,255,223,61
	.byte 255,255,231,19,255,255,251,15,255,255,253,31,255,255,253,27,255
	.byte 255,253,27,255,255,253,75,255,255,253,115,255,15,250,124,255,243
	.byte 255,63,255,253,255,79,255,254,252,227,127,255,251,241,191,255,247
	.byte 253,191,255,239,253,223,255,111,254,207,255,15,255,247,255,207
	.byte 255,251,255,199,255,157,63,227,255,78,127,128,255,241,248,14,255
	.byte 255,247,15,255,255,7,128,255,255,255,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255

rtogi2_bits:
	.byte 255,255,255,252,255,255,127,253,255,255,191,253,255,255,223,253
	.byte 255,255,231,125,255,255,251,115,255,255,253,111,255,255,253,91
	.byte 255,255,253,91,255,255,253,59,255,255,125,62,255,15,250,89,255
	.byte 243,255,95,255,253,127,104,255,254,252,115,127,255,251,15,188,255
	.byte 247,127,186,255,239,129,214,255,111,128,206,255,15,207,253,255
	.byte 207,255,251,255,199,255,135,63,227,255,127,127,128,255,255,248,14
	.byte 255,255,247,15,255,255,7,128,255,255,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255

sleep1_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,63,224,255,255
	.byte 255,247,255,255,255,250,255,255,255,253,255,255,255,250,224,255
	.byte 127,255,247,255,63,224,251,255,255,255,224,255,255,255,255,255
	.byte 255,255,255,254,255,255,127,253,255,255,190,253,255,127,221,253
	.byte 255,191,193,249,255,199,235,245,255,217,231,235,255,238,255,231
	.byte 255,238,255,231,127,239,255,199,191,239,255,211,191,95,254,212
	.byte 191,223,113,151,191,223,239,171,191,191,191,164,127,127,0,179,255
	.byte 192,15,155,255,31,96,192,255,255,255,255,255,255,255,255

sleep2_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	.byte 255,255,255,255,255,192,255,255,255,239,195,255,255,243,239,255
	.byte 255,251,119,254,255,192,131,254,255,127,159,254,255,63,222,253
	.byte 255,135,192,249,255,217,237,245,255,222,243,235,127,239,255,231
	.byte 127,239,255,231,127,239,255,199,191,239,255,213,191,95,252,214
	.byte 191,223,115,151,191,223,239,171,191,191,191,164,127,127,0,179,255
	.byte 192,15,155,255,31,96,192,255,255,255,255,255,255,255,255

up1_bits:
	.byte 255,63,252,255,255,193,131,255,255,247,239,255,255,217,155,255
	.byte 255,221,187,255,255,221,187,255,255,254,127,255,255,224,7,255,255
	.byte 254,127,255,255,221,189,255,255,225,131,255,255,249,159,255,127
	.byte 192,3,254,63,248,31,253,191,253,191,253,191,253,191,253,191,254
	.byte 127,253,191,255,255,253,127,255,255,254,127,255,255,254,127,255
	.byte 255,254,127,255,255,254,255,254,127,255,255,249,159,255,255,135
	.byte 225,255,255,191,253,255,255,191,253,255,255,191,253,255,255,191
	.byte 253,255,255,127,254,255,255,255,255,255,255,255,255,255

up2_bits:
	.byte 255,63,252,255,127,192,3,254,191,244,47,253,191,217,155,253,191
	.byte 221,187,253,191,221,187,253,191,254,127,253,191,224,7,253,191,254
	.byte 127,253,191,221,189,253,127,225,131,254,127,251,223,254,127,199
	.byte 227,254,127,255,255,254,255,254,127,255,255,242,79,255,255,124,62
	.byte 255,255,190,125,255,127,191,253,254,127,191,253,254,127,191,253
	.byte 254,127,191,253,254,127,191,253,254,127,255,255,254,127,63,252
	.byte 254,255,190,125,255,255,222,123,255,255,238,119,255,255,246,111
	.byte 255,255,249,159,255,255,255,255,255,255,255,255,255

upleft1_bits:
	.byte 255,255,248,255,127,0,251,255,191,135,251,255,31,218,251,255,201
	.byte 221,251,255,231,222,251,255,239,223,251,255,239,255,251,255,239
	.byte 255,193,255,223,255,62,254,223,255,255,253,63,255,255,251,255,254
	.byte 255,247,255,254,255,247,255,254,255,239,255,254,255,223,255,60
	.byte 255,223,255,221,255,223,255,205,255,223,255,221,255,207,255,219
	.byte 255,207,255,155,255,223,255,39,63,155,255,47,62,176,255,15,60,100
	.byte 255,143,15,108,255,239,225,159,255,15,252,255,255,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255

upleft2_bits:
	.byte 255,255,255,255,255,255,255,255,255,0,255,255,127,79,254,255,191
	.byte 248,193,255,159,63,223,255,167,71,239,255,191,119,239,255,161,127
	.byte 247,255,13,127,247,255,57,255,235,255,115,252,219,255,231,255,189
	.byte 241,207,175,126,246,191,255,255,246,127,254,127,251,255,253,127
	.byte 243,255,251,191,245,255,247,255,205,255,239,255,191,255,239,223
	.byte 191,255,239,191,191,255,239,127,191,255,223,127,120,255,223,127
	.byte 119,255,191,127,111,255,127,112,111,255,255,111,95,255,255,111,63
	.byte 255,255,111,255,255,255,111,255,255,255,159,255

upright1_bits:
	.byte 255,31,255,255,255,223,0,254,255,223,225,253,255,223,91,248,255
	.byte 223,187,147,255,223,123,231,255,223,251,247,255,223,255,247,255
	.byte 131,255,247,127,124,255,251,191,255,255,251,223,255,255,252,239
	.byte 255,127,255,239,255,127,255,247,255,127,255,251,255,127,255,251
	.byte 255,60,255,251,255,187,255,251,255,179,255,243,255,187,255,243
	.byte 255,219,255,251,255,217,255,217,252,228,255,13,124,244,255,38,60
	.byte 240,255,54,240,241,255,249,135,247,255,255,63,240,255,255,255,255
	.byte 255,255,255,255,255,255,255,255,255,255,255,255,255

upright2_bits:
	.byte 255,255,255,255,255,255,255,255,255,255,0,255,255,127,242,254,255
	.byte 131,31,253,255,251,252,249,255,247,226,229,255,247,238,253,255
	.byte 239,254,133,255,239,254,176,255,215,255,156,255,219,63,206,143
	.byte 189,255,231,111,126,245,243,111,255,255,253,223,254,127,254,207
	.byte 254,191,255,175,253,223,255,179,255,239,255,253,255,247,255,253
	.byte 251,247,255,253,253,247,255,253,254,247,255,30,254,251,255,238
	.byte 254,251,255,246,254,253,255,246,14,254,255,250,246,255,255,252
	.byte 246,255,255,255,246,255,255,255,246,255,255,255,249,255,255

utogi1_bits:
	.byte 255,213,205,255,255,213,181,255,127,20,180,255,255,193,3,255,255
	.byte 245,111,255,255,217,91,255,255,220,59,255,255,220,59,255,255,254
	.byte 127,255,127,224,7,254,127,254,127,255,255,216,157,255,255,226,163
	.byte 255,255,252,63,255,255,225,135,255,255,253,191,255,255,254,127
	.byte 255,127,255,255,254,127,255,255,254,127,255,255,254,79,255,255
	.byte 242,23,254,127,236,247,252,63,239,239,255,255,247,31,135,225,248
	.byte 255,184,29,255,255,223,253,255,255,239,254,255,255,111,255,255
	.byte 255,159,255,255,255,255,255,255,255,255,255,255

utogi2_bits:
	.byte 255,217,213,255,255,214,213,255,255,22,20,255,255,194,195,255,255
	.byte 246,207,255,255,218,187,255,255,220,187,255,255,220,187,255,255
	.byte 254,127,255,127,224,7,254,127,255,127,255,255,216,157,255,255,226
	.byte 163,255,255,252,63,255,255,225,135,255,255,253,191,255,255,254
	.byte 127,255,127,255,255,254,127,255,255,254,127,255,255,254,79,255
	.byte 255,242,23,254,127,236,247,252,63,239,239,255,255,247,31,135,225
	.byte 248,255,184,29,255,255,191,251,255,255,127,247,255,255,255,246
	.byte 255,255,255,249,255,255,255,255,255,255,255,255,255

;;;

cycleSTART:
	.word 150, mati2_bits, 	50, awake_bits
cycleAWAKE:
	.word 50, awake_bits,	50, mati2_bits
cycleYAWN:
	.word 100, mati2_bits, 	150, mati3_bits
cycleSLEEP:
	.word 50, sleep1_bits, 	50, sleep2_bits
cycleSCRATCH:
	.word 50, kaki1_bits, 	50, kaki2_bits
cycleLICK:
	.word 50, mati2_bits, 	50, jare2_bits
cycleCHASE:
	.word 50, awake_bits,	50, mati2_bits
scratchLEFT:
	.word 25, ltogi1_bits,	25, ltogi2_bits
scratchRIGHT:
	.word 25, rtogi1_bits, 	25, rtogi2_bits
scratchTOP:
	.word 25, utogi1_bits, 	25, utogi2_bits
scratchBOTTOM:
	.word 25, dtogi1_bits, 	25, dtogi2_bits

rundirection:
	.word upleft1_bits, upleft2_bits, upright1_bits, upright2_bits
	.word dwleft1_bits, dwleft2_bits, dwright1_bits, dwright2_bits
	.word up1_bits,     up2_bits,     up1_bits,      up2_bits
	.word down1_bits,   down2_bits,   down1_bits,    down2_bits
	.word left1_bits,   left2_bits,   right1_bits,   right2_bits
	.word left1_bits,   left2_bits,   right1_bits,   right2_bits

;;;, ----------------------------------------------------------------------

	.section .vectors, "ax", @progbits
	.rept 16
	.short RESET
	.endr
	.end

;;;, ----------------------------------------------------------------------
